home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 46 / Amiga Format CD46 (1999-10-20)(Future Publishing)(GB)[!][issue 1999-12].iso / -serious- / programming / other / tandem / teaching / 65.asm < prev    next >
Assembly Source File  |  1999-09-06  |  11KB  |  432 lines

  1. * 65.asm  TLtabs     version 0.01     8.6.97
  2.  
  3.  
  4.  include 'Front.i'
  5.  
  6.  
  7. ; ***** Important notes about this Program *****
  8.  
  9. ; TLtabs is used to draw a set of thumbtab cards on a window, and monitor
  10. ; them. tandem.library has several sets of routines like this:
  11.  
  12. ; - TLtabs,TLtabmon    - for a set of thumbtab cards
  13. ; - TLslider,TLslimon  - for a slider
  14. ; - TLscroll           - for a window scroller
  15. ; - TLbutprt,TLbutmon  - for a set of buttons
  16.  
  17. ; Unlike tandem.library requesters, which take over everything and use their
  18. ; own window, the above are rendered on a window with other things, and
  19. ; share the window. You can of course use gadtools.library gadgets, which
  20. ; are sophisticated, as each gadget sends its own special IDCMP messages to
  21. ; you. But tandem.library requires you to monitor each TLkeyboard you get,
  22. ; to see if the input is from any of the above.
  23.  
  24. ; Follow the logic of the program below to see how you do this. You first
  25. ; set up a set of tab cards, & decide what you will do in each. You can of
  26. ; course have all sorts of other things on the window. Basically, the user
  27. ; is expected to click things to activate them, so what your program must
  28. ; do, is see what gets clicked, and activate it for the user, until
  29. ; something else gets clicked.
  30.  
  31. ; The program below sets up a set of 4 tab cards, which do various things.
  32. ; You will see how to go from card to card under user control (by clicking
  33. ; thumb tabs), or under program control. You will see how to edit strings on
  34. ; a tab card, how to use buttons, &c.
  35.  
  36. ; You will see that this program uses a set of 12 tiny grafix which you can
  37. ; show with TLpict - these are useful for all sorts of things, but they
  38. ; are inflexible in that TLpict doesn't allow you to specify the pens used
  39. ; to draw them. The grafix allow rounded corners on a bevelled box, arrows
  40. ; pointing in 4 directions, a checkmark and a tiny tandem.library logo.
  41.  
  42. ; I didn't make this program font-sensitive, or it would have been too long
  43. ; and messy to take in easily.
  44.  
  45.  
  46. wdth: EQU 160               ;tabcard minimum body width (20 chrs)
  47. hght: EQU 120               ;tabcard body height
  48. xpos: EQU 20                ;tabcard xpos
  49. ypos: EQU 10                ;tabcard ypos
  50.  
  51.  
  52. ;data for tabs
  53. tab: ds.w 1                 ;currently operative tab
  54.  
  55. ;tab1 data
  56. rec: ds.w 1                 ;-1recessed,0normal
  57. t1ps: ds.w 2                ;bev box posn
  58.  
  59. ;tab2 data
  60. name: ds.b 20               ;name as entered
  61.  
  62.  
  63. strings: dc.b 0
  64. st_1: dc.b 'TLTabs demonstration',0 ;1
  65.  dc.b 'Abc\Defg\Hij\Klmn',0 ;2
  66.  dc.b 'I am Tab card Abc!',0 ;3
  67.  dc.b 'I am Tab card Defg!',0 ;4
  68.  dc.b 'I am Tab card Hij!',0 ;5
  69.  dc.b 'I am Tab card Klmn!',0 ;6
  70.  dc.b 'TLpict icons 0-B...',0 ;7
  71.  dc.b '0 1 2 3 4 5 6 7',0 ;8
  72.  dc.b '8 9 A B C D E F',0 ;9
  73.  dc.b 'Click the box',0 ;10
  74.  dc.b 'for a shriek',0 ;11
  75.  dc.b 'for a query',0 ;12
  76.  dc.b '!',0 ;13
  77.  dc.b '?',0 ;14
  78.  dc.b 'Enter your name...',0 ;15
  79.  dc.b 'Name',0 ;16
  80.  dc.b 'Quit',0 ;17
  81.  dc.b 'Art!',0 ;18
  82.  dc.b 'Go to Tabcard Abc',0 ;19
  83.  
  84.  ds.w 0
  85.  
  86.  
  87. * demonstrate TLtabs
  88. Program:
  89.  TLwindow #0,#0,#0,#380,#120,#640,#256,#-1,#st_1 ;open window 0
  90.  beq Pr_quit
  91.  
  92.  clr.w rec                 ;initialise data
  93.  clr.b name
  94.  
  95.  TLtabs #2,#wdth,#hght     ;set up tabs:  heders in string 2, body 160X120
  96.  
  97. Pr_draw:
  98.  TLtabs #0,#1,#xpos,#ypos  ;draw with tab1 active
  99.  
  100.  move.l xxp_AcWind(a4),a5  ;a5 is currently popped window       } used by
  101.  moveq #xpos+4,d6          ;d6 is lhs of printable area of body } T1render
  102.  moveq #ypos+1,d7                                               }
  103.  add.l xxp_tblh(a4),d7     ;d7 is top of printable area of body }
  104.  
  105.  bsr T1render              ;draw tab1
  106.  
  107. Pr_wait:
  108.  TLkeyboard                ;get keyboard
  109.  
  110. Pr_pick:
  111.  TLwupdate
  112.  cmp.b #$1B,d0             ;quit if Esc
  113.  beq Pr_quit
  114.  cmp.b #$93,d0             ;quit if Close window
  115.  beq Pr_quit
  116.  
  117. *******                    ;note: we would monitor for other things on the
  118. *******                    ;window here, if there were other things on it.
  119. *******                    ;If yes, process them, & go to Pr_wait.
  120.  
  121.  move.l xxp_AcWind(a4),a5  ;a5 is currently popped window
  122.  moveq #xpos+4,d6          ;d6 is lhs of printable area of body
  123.  moveq #ypos+1,d7
  124.  add.l xxp_tblh(a4),d7     ;d7 is top of printable area of body
  125.  
  126.  move.l d0,d4              ;save d0
  127.  cmp.b #$80,d0             ;only call TLtabmon if left mouse button
  128.  bne.s Pr_cont             ;else go monitor whichever tabcard at front
  129.  
  130.  TLtabmon d1,d2,#xpos,#ypos ;see if thumbtabs clicked
  131.  beq.s Pr_cont             ;no, go monitor whichever tabcard at front
  132.  
  133.  move.w d0,tab             ;yes, note which tab is now operative
  134.  cmpi.w #2,d0              ;go draw whichever thumbtab clicked
  135.  bcs Pr_t1dr
  136.  beq Pr_t2dr
  137.  cmpi.w #4,d0
  138.  bcs Pr_t3dr
  139.  bra Pr_t4dr
  140.  
  141. Pr_cont:
  142.  move.l d4,d0              ;restore d0 from TLkeboard
  143.  sub.w xxp_LeftEdge(a5),d1 ;make lmb relative to window printable area
  144.  sub.w xxp_TopEdge(a5),d2
  145.  
  146.  cmpi.w #2,tab             ;branch to whichever tab
  147.  bcs Pr_tab1               ;(each test if the TLKeyboard is relevent to it)
  148.  beq Pr_tab2               ;(if so, they act upon it, else discard it)
  149.  cmpi.w #4,tab
  150.  bcs Pr_tab3
  151.  bra Pr_tab4
  152.  
  153. Pr_t1dr:                   ;draw tab1
  154.  bsr T1render
  155.  bra Pr_wait
  156.  
  157. Pr_t2dr:                   ;draw tab2
  158.  bsr T2render
  159.  bra Pr_wait
  160.  
  161. Pr_t3dr:                   ;draw tab3
  162.  bsr T3render
  163.  bra Pr_wait
  164.  
  165. Pr_t4dr:                   ;draw tab4
  166.  bsr T4render
  167.  bra Pr_wait
  168.  
  169.  
  170. Pr_tab1:                   ;monitor tab1
  171.  bsr T1monitor
  172.  bra Pr_wait
  173.  
  174. Pr_tab2:                   ;monitor tab2
  175.  clr.l xxp_kybd(a4)        ;clear in case Reqedit ends with click
  176.  bsr T2monitor             ;do the monitoring
  177.  tst.l xxp_kybd(a4)        ;was there a click?
  178.  beq Pr_wait               ;no, wait for one
  179.  bra.s Pr_ccyc             ;yes, get it as an input
  180.  
  181. Pr_tab3:                   ;monitor tab3 (sets EQ if quit requested)
  182.  bsr T3monitor
  183.  beq Pr_quit               ;go if quit requested
  184.  bra Pr_wait
  185.  
  186. Pr_tab4:                   ;monitor tab4
  187.  bsr T4monitor
  188.  bra Pr_wait
  189.  
  190. Pr_ccyc:                   ;process a keyboard input inherited from
  191.  move.l xxp_kybd(a4),d0    ;    monitoring a page
  192.  move.l xxp_kybd+4(a4),d1
  193.  move.l xxp_kybd+8(a4),d2
  194.  cmp.b #$1B,d0             ;(don't quit from here if Esc)
  195.  bne Pr_pick
  196.  clr.b d0
  197.  bra Pr_pick
  198.  
  199. Pr_done:                   ;clear tabs area & quit (Esc or close window)
  200.  TLtabs #0,#0,#xpos,#ypos
  201.  
  202. Pr_quit:
  203.  rts
  204.  
  205.  
  206. * render tab1
  207. T1render:
  208.  TLreqarea d6,d7,#wdth,#hght,#3 ;clear display area in case re-calling
  209.  
  210.  move.l xxp_AcWind(a4),a5  ;print title
  211.  move.w #$0203,xxp_FrontPen(a5)
  212.  TLstring #3,d6,d7
  213.  subq.b #1,xxp_FrontPen(a5)
  214.  
  215.  move.l d7,d2              ;print string 10
  216.  add.w #20,d2
  217.  move.l d6,d1
  218.  TLstring #10,d1,d2
  219.  
  220.  tst.w rec                 ;go if recessed
  221.  bmi .t1rc
  222.  
  223.  addq.w #8,d2              ;'for a shriek...'
  224.  TLstring #11,d1,d2
  225.  subq.w #4,d2
  226.  add.w #108,d1
  227.  TLpict #6,d1,d2
  228.  add.w #26,d1
  229.  TLstring #14,d1,d2
  230.  subq.w #6,d2
  231.  sub.w #12,d1
  232.  TLreqbev d1,d2,#36,#20
  233.  bra .t1cu
  234.  
  235. .t1rc:                     ;print 'for a query..'
  236.  addq.w #8,d2
  237.  TLstring #12,d1,d2
  238.  subq.w #4,d2
  239.  add.w #108,d1
  240.  TLpict #6,d1,d2
  241.  add.w #26,d1
  242.  TLstring #13,d1,d2
  243.  subq.w #6,d2
  244.  sub.w #12,d1
  245.  TLreqbev d1,d2,#36,#20,rec
  246.  
  247. .t1cu:
  248.  move.w d1,t1ps            ;remember where the reqbev was (for T1monitor)
  249.  move.w d2,t1ps+2
  250.  
  251.  TLstring #7,#24,#88       ;show TLPict samples
  252.  TLstring #8,#24,#96
  253.  TLpict #0,#24,#108
  254.  TLpict #1,#40,#108
  255.  TLpict #2,#56,#108
  256.  TLpict #3,#72,#108
  257.  TLpict #4,#88,#108
  258.  TLpict #5,#104,#108
  259.  TLpict #6,#120,#108
  260.  TLpict #7,#136,#108
  261.  TLstring #9,#24,#120
  262.  TLpict #8,#24,#132
  263.  TLpict #9,#40,#132
  264.  TLpict #10,#56,#132
  265.  TLpict #11,#72,#132
  266.  TLpict #12,#88,#132
  267.  TLpict #13,#104,#132
  268.  TLpict #14,#120,#132
  269.  TLpict #15,#136,#132
  270.  rts
  271.  
  272.  
  273. * render tab2
  274. T2render:
  275.  move.l xxp_AcWind(a4),a5  ;print title
  276.  move.w #$0203,xxp_FrontPen(a5)
  277.  TLstring #4,d6,d7
  278.  subq.b #1,xxp_FrontPen(a5)
  279.  
  280.  TLstring #15,#24,#60      ;print instructions, bev
  281.  TLstring #16,#24,#72
  282.  TLreqbev #68,#71,#100,#10
  283.  
  284.  sub.w #20,a7              ;print name (so far)
  285.  move.l a7,a0
  286.  move.l #xxp_xtext,(a0)+
  287.  move.l #name,(a0)+
  288.  move.l #xxp_xcrsr,(a0)+
  289.  move.l #-1,(a0)+
  290.  clr.l (a0)
  291.  TLreqedit #72,#72,a7
  292.  add.w #20,a7
  293.  rts
  294.  
  295.  
  296. * render tab3
  297. T3render:
  298.  move.l xxp_AcWind(a4),a5  ;print title
  299.  move.w #$0203,xxp_FrontPen(a5)
  300.  TLstring #5,d6,d7
  301.  subq.b #1,xxp_FrontPen(a5)
  302.  
  303.  TLstring #17,#40,#40      ;quit button
  304.  TLreqbev #38,#39,#34,#10
  305.  
  306.  TLreqarea #74,#75,#60,#30,#0 ;draw a picture
  307.  TLreqbev #74,#75,#60,#30
  308.  TLreqarea #82,#79,#44,#22,#3
  309.  TLreqbev #82,#79,#44,#22
  310.  TLpict #0,#82,#79
  311.  TLpict #3,#118,#79
  312.  TLpict #4,#82,#93
  313.  TLpict #5,#118,#93
  314.  TLpict #11,#100,#86
  315.  TLpict #8,#100,#107
  316.  TLstring #18,#88,#116
  317.  rts
  318.  
  319.  
  320. * render tab4
  321. T4render:
  322.  move.l xxp_AcWind(a4),a5  ;print title
  323.  move.w #$0203,xxp_FrontPen(a5)
  324.  TLstring #6,d6,d7
  325.  subq.b #1,xxp_FrontPen(a5)
  326.  
  327.  TLstring #19,#36,#70
  328.  TLreqbev #34,#69,#142,#10
  329.  rts
  330.  
  331.  
  332. * monitor tab1
  333. T1monitor:
  334.  cmp.b #$80,d0             ;quit unless lmb
  335.  bne.s T1_quit
  336.  
  337.  sub.w t1ps,d1             ;quit unless in bev
  338.  bcs.s T1_quit
  339.  sub.w t1ps+2,d2
  340.  bcs.s T1_quit
  341.  cmp.w #36,d1
  342.  bcc.s T1_quit
  343.  cmp.w #20,d2
  344.  bcc.s T1_quit
  345.  
  346.  move.w rec,d0             ;flip-flop rec
  347.  eori.w #-1,d0
  348.  move.w d0,rec
  349.  bsr T1render
  350.  
  351. T1_quit:
  352.  rts
  353.  
  354.  
  355. * monitor tab2:
  356. T2monitor:
  357.  cmp.b #$80,d0             ;quit unless lmb
  358.  bne.s T2_quit
  359.  
  360.  sub.w #72,d1              ;quit unless clicked in box
  361.  bcs.s T2_quit
  362.  sub.w #72,d2
  363.  bcs.s T2_quit
  364.  cmp.w #96,d1
  365.  bcc.s T2_quit
  366.  cmp.w #8,d2
  367.  bcc.s T2_quit
  368.  
  369.  sub.w #20,a7              ;edit name
  370.  move.l a7,a0
  371.  move.l #xxp_xtext,(a0)+
  372.  move.l #name,(a0)+
  373.  move.l #xxp_xmaxc,(a0)+
  374.  move.l #12,(a0)+
  375.  clr.l (a0)+
  376.  TLreqedit #72,#72,a7
  377.  add.w #20,a7
  378.  
  379.  move.l xxp_FWork(a4),a0   ;tfr name as edited to name
  380.  lea name,a1
  381. T2_tfr:
  382.  move.b (a0)+,(a1)+
  383.  bne T2_tfr
  384.  
  385. T2_quit:
  386.  rts
  387.  
  388.  
  389. * monitor tab3:
  390. T3monitor:
  391.  cmp.b #$80,d0             ;don't quit unless lmb
  392.  bne.s T3_unqt
  393.  
  394.  sub.w #38,d1              ;don't quit if clicked outside quit button
  395.  bcs.s T3_unqt
  396.  cmp.w #34,d1
  397.  bcc.s T3_unqt
  398.  sub.w #39,d2
  399.  bcs.s T3_unqt
  400.  cmp.w #10,d2
  401.  bcc.s T3_unqt
  402.  
  403. T3_quit:                   ;exit here to quit
  404.  moveq #0,d0
  405.  rts
  406.  
  407. T3_unqt:                   ;exit here NOT to quit
  408.  moveq #-1,d0
  409.  rts
  410.  
  411.  
  412. * monitor tab4:
  413. T4monitor:
  414.  cmp.w #$80,d0             ;go unless lmb click
  415.  bne.s T4_quit
  416.  
  417.  sub.w #34,d1              ;go unless button clicked
  418.  bcs.s T4_quit
  419.  cmp.w #134,d1
  420.  bcc.s T4_quit
  421.  sub.w #69,d2
  422.  bcs.s T4_quit
  423.  cmp.w #10,d2
  424.  bcc.s T4_quit
  425.  
  426.  move.w #1,tab            ;note tab1 in front
  427.  TLtabs #0,#1,#20,#10     ;bring tab1's thumbtab forward
  428.  bsr T1render             ;render tab1 body (needed data still in A5,D6,D7)
  429.  
  430. T4_quit:
  431.  rts
  432.